package artibella.media 
{
	import artibella.media.controls.AController;
	
	import flash.errors.IllegalOperationError;
	import flash.media.SoundTransform;
	import flash.utils.Dictionary;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class SoundManager 
	{
		private static var _instance:SoundManager;
		
		private var _tab:Vector.<AMedia>;
		
		public function SoundManager( c:PrivateClass = null ) 
		{
			if( !c ) {
				throw new IllegalOperationError( 'Error : singleton pattern' );
			} else {

				_tab = new Vector.<AMedia>();
			}
		}
		
		public static function get instance():SoundManager
		{
			return _instance || ( _instance = new SoundManager( new PrivateClass() ) );
		}
		
		/////// 
		
		public function playSound( t:AMedia ):void
		{
			var found:Boolean = false;
			
			for (var i:int = 0; i < _tab.length; i++)
			{
				if ( _tab[i].url != t.url ){
					_tab[i].stop();
				} else {
					found = true;
				}
			}
			
			if ( !found ) _tab.push( t );
		}
	}
}

/// - - -

class PrivateClass { }